Python 网络驱动程序

托马斯·麦克唐纳

我试图从一家网上商店抓取产品,类似于Dropified从阿里快递中抓取商品的方式,

当前解决方案(它的设置方式只会尝试访问第一项):

 from bs4 import BeautifulSoup
import requests
import time
import re

# Get search inputs from user
search_term = raw_input('Search Term:')

# Build URL to imdb.com
aliURL = 'https://www.aliexpress.com/wholesale?SearchText=%(q)s'
payload = {'q': search_term, }

# Get resulting webpage
r = requests.get(aliURL % payload)

# Build 'soup' from webpage and filter down to the results of search
soup = BeautifulSoup(r.text, "html5lib")
titles = soup.findAll('a', attrs = {'class': 'product'})


itemURL = titles[0]["href"]
seperatemarker = '?'
seperatedURL = itemURL.split(seperatemarker, 1)[0]

seperatedURL = "http:" + seperatedURL

print seperatedURL

IR = requests.get(seperatedURL)
Isoup = BeautifulSoup(IR.text, "html5lib")

productname = Isoup.findAll('h1')

print productname

此解决方案假设页面上的项目不需要 javascript,如果该项目需要,它只会在文档准备好之前检索初始页面。

我意识到我可以使用 python 网络驱动程序,但我想知道是否有任何其他解决方案可以解决这个问题,可以轻松实现网络抓取工具的自动化。

米凯尔·奥尔法尼安

结帐seleniumphantomjsseleniumphantomjs处理大部分与页面上 JS 生成内容相关的问题。你甚至不需要再考虑这些事情了。
如果您正在抓取许多页面并希望加快速度,您可能希望异步执行操作。对于中小型设置,您可以使用RQ. 对于较大的项目,您可以使用celery. 这些工具允许您同时抓取多个页面(尽管不是同时)。
请注意,到目前为止我提到的工具与asyncio其他async框架无关
我尝试抓取一些电子商务页面,并注意到该程序花费了 80% 的时间等待 HTTP 调用返回某些内容。使用上述工具,您可以将 80% 减少到 10% 或更少。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python Selenium Chrome Web驱动程序

如何在Spark中设置驱动程序的python版本?

在Docker中设置cassandra驱动程序(python)

如何在python中隐藏Chrome驱动程序?

检测到带有chrome驱动程序的Python Selenium Web驱动程序

尝试使用python安装cassandra驱动程序时出错

使用python cassandra驱动程序选择和解码Blob

Selenium驱动程序中的Python增量字符串号

使用python硒驱动程序下载pdf文件

Python Cassandra驱动程序Readtimeout

(python)使用@parameterized lib声明驱动程序?

无法保持对Selenium Python驱动程序中元素的关注

Selenium:循环Web驱动程序(Python)

Python peewee.ImproperlyConfigured:未安装MySQL驱动程序

Python:Selenium驱动程序find_elements_by_xpath:问题

从Python访问Windows驱动程序

rethinkdb index-rebuild抱怨缺少python驱动程序

cassandra python驱动程序绑定到int

禁用python chrome驱动程序扩展,而不会丢失驱动程序路径

Cassandra模型的CQL(datastax驱动程序:python)

使用 Python 的 Selenium 网络驱动程序

Cassandra Python 驱动程序 ReadTimeout

如何使用 selenium chrome 驱动程序在 Python 中按名称过滤网络调用条目?

通过网络驱动程序python查找文本框

在 Python Web 驱动程序中检索 HTML 元素对象

如何使用 selenium Web 驱动程序单击元素(Python)

uvicorn 为 gelf 驱动程序抑制 python 的系统日志

硒网络驱动程序python

使用 Python Cassandra 驱动程序进行大号。查询数