我正在使用像这样的Firefox无头:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium import webdriver
import os
import sys
# Set the MOZ_HEADLESS environment variable which casues Firefox to
# start in headless mode.
os.environ['MOZ_HEADLESS'] = '1'
# Select your Firefox binary.
binary = FirefoxBinary('/usr/bin/firefox', log_file=sys.stdout)
# Start selenium with the configured binary.
driver = webdriver.Firefox(firefox_binary=binary)
Run Code Online (Sandbox Code Playgroud)
但现在我想添加一个需要用户/密码的http代理.搜索后,我尝试了以下内容:
from selenium.webdriver.common.proxy import Proxy, ProxyType
myProxy = "xx.xx.xx.xx:80"
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': myProxy,
'ftpProxy': myProxy,
'sslProxy': myProxy,
'noProxy': '' # set this value as desired
})
driver …Run Code Online (Sandbox Code Playgroud) 为什么不request下载此网页的回复?
#!/usr/bin/python
import requests
headers={ 'content-type':'application/x-www-form-urlencoded; charset=UTF-8',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0',
'Referer' : 'http://sportsbeta.ladbrokes.com/football',
}
payload={'N': '4294966750',
'facetCount_156%23327': '12',
'facetCount_157%23325': '8',
'form-trigger':'moreId',
'moreId':'156%23327',
'pageId':'p_football_home_page',
'pageType':'EventClass',
'type':'ajaxrequest'
}
url='http://sportsbeta.ladbrokes.com/view/EventDetailPageComponentController'
r = requests.post(url, data=payload, headers=headers)
Run Code Online (Sandbox Code Playgroud)
这些是POST我在Firebug中看到的参数,并且收到的回复包含一个列表(足球联赛),但是当我像这样运行我的python脚本时,我什么也得不到.
(您可以通过单击链接See All左侧导航栏的竞争部分并查看Firebug中的XHR 来查看Firefox中的请求.Wirebug响应按预期显示HTML正文.)
任何想法?我%对有效载荷中符号的处理是否会造成任何麻烦?
编辑:尝试使用会话
from requests import Request, Session
#turn post string into dict:
def parsePOSTstring(POSTstr):
paramList = POSTstr.split('&')
paramDict = dict([param.split('=') for param in paramList])
return paramDict …Run Code Online (Sandbox Code Playgroud) 我正在使用以下requirements.txtpip:
Django==1.4.3
Pillow==2.4.0
South==0.7.5
amqp==1.4.5
anyjson==0.3.3
argparse==1.2.1
billiard==3.3.0.18
boto==2.4.1
celery==3.1.12
cffi==0.8.6
cryptography==0.5.4
dj-database-url==0.2.0
django-annoying==0.7.6
django-appconf==0.6
django-articles==2.4.1
django-celery==3.1.10
django-compressor==1.3
django-debug-toolbar==1.2.1
django-jsonfield==0.9.13
django-pdb==0.4.0
django-postmark==0.1.6
django-s3-folder-storage==0.2
django-storages==1.1.4
docopt==0.6.1
facebook-sdk==0.4.0
google-api-python-client==1.2
gunicorn==0.15.0
httplib2==0.9
ipython==2.1.0
itsdangerous==0.24
kombu==3.0.20
mailchimp==2.0.8
path-and-address==0.2.0
psycopg2==2.4.5
pyOpenSSL==0.14
pycparser==2.10
pyparsing==2.0.2
python-dateutil==2.2
pytz==2013b
requests==2.3.0
six==1.8.0
sqlparse==0.1.11
tweepy==2.3.0
wsgiref==0.1.2
Run Code Online (Sandbox Code Playgroud)
在我添加之前,事情一直在进行
cffi==0.8.6
cryptography==0.5.4
google-api-python-client==1.2
httplib2==0.9
pyOpenSSL==0.14
pycparser==2.10
pyparsing==2.0.2
Run Code Online (Sandbox Code Playgroud)
我为了使用谷歌日历API而添加,因为它SignedJwtAssertionCredentials取决于pyOpenSSL.
现在,当我推送到heroku时,我在构建过程中遇到了错误,看似与之相关six,cffi或者cyrptography:
完整的构建日志在这里,但一些相关的片段:
Fetching repository, done.
-----> Python app detected
-----> Noticed cffi. …Run Code Online (Sandbox Code Playgroud) 我正在尝试弄清楚当连接到Linux上的MS-SQL服务器时,这两个拼图是如何交互在一起的.
据我了解,FreeTDS是用于与MS-SQL交谈的协议(即一组规则),它实际上是在进行交谈.Unixodbc是一个实现ODBC API的驱动程序,即我实现了一组函数.
为什么两件事都必要?任何人都可以详细说明我对这两件事实际做了什么的粗略理解吗?
使用requestspython lib,我发出一个GET请求,并处理Timeout异常(以及我未在此处显示的其他异常),如
import requests
timeout1=20
timeout2=40
try:
#first attempt
resp = requests.get(base_url+resource, params=payload, headers=headers,
timeout=timeout1)
except requests.exceptions.Timeout:
#timed out, retry once
try:
resp = requests.get(base_url+resource, params=payload, headers=headers,
timeout=timeout2)
return resp.json()
except requests.exceptions.RequestException as e:
#Still failed; return error code
return -1
Run Code Online (Sandbox Code Playgroud)
这在大多数情况下工作正常,但有时我的程序只是完全退出错误socket.timeout: timed out,而不是抛出requests.exceptions.Timeout并被捕获和处理.
为什么请求lib的行为如此?我该怎么处理?
我有一些代码可以将 Scrapy 抓取的数据写入 SQL 服务器数据库。数据项包括一些基本的酒店数据(名称、地址、评级...)和一些带有相关数据(价格、入住率等)的房间列表。可以有多个 celery 线程和多个服务器运行此代码并同时写入数据库不同的项目。我遇到死锁错误,例如:
[Failure instance: Traceback: <class 'pyodbc.ProgrammingError'>:
('42000', '[42000] [FreeTDS][SQL Server]Transaction (Process ID 62)
was deadlocked on lock resources with another process and has been
chosen as the deadlock victim. Rerun the transaction. (1205) (SQLParamData)')
Run Code Online (Sandbox Code Playgroud)
实际执行插入/更新的代码示意如下:
1) Check if hotel exists in hotels table, if it does update it, else insert it new.
Get the hotel id either way. This is done by `curs.execute(...)`
2) Python loop over the hotel rooms scraped. For each room …Run Code Online (Sandbox Code Playgroud) 是否可以将 Firebase 分析挂钩到远程 REST API 端点?
更具体地说,假设我有一个远程 REST API,它有一个端点来计算我的每个用户上传的平均视频数/api/videos/get_average_count。我可以以某种方式将该统计信息集成到 Firebase 分析中吗?(我认为 Firebase 分析中没有报告 API?)
或者,无论如何,我是否可以从其他分析(在前端跟踪)中获取 Firebase 数据并将该数据集成/嵌入到我自己的后端托管的自定义管理中?
我有一个表格的XML文件:
<PlayersList>
<player>
<username>Someuser</username>
<network>Somenetwork</network>
<country>France</country>
<blocked>False</blocked>
<resetDate>NA</resetDate>
<Stat1>1665</Stat1>
<Stat2>-5.47</Stat2>
<Stat3>15.07</Stat3>
<Stat4>-16.8</Stat4>
<Stat5>-9104.47</Stat5>
<Stat6>25087.75</Stat6>
<Stat7>17965.79</Stat7>
<Stat8>2011-04-17 03:33</Stat8>
<Stat9>28</Stat9>
<Stat10>5.9</Stat10>
<Stat11>283</Stat11>
<Stat12>-33.6</Stat12>
<Stat13>22.3</Stat13>
<Stat14>460.4</Stat14>
<Stat15>57.5</Stat15>
</player>
.
.
</PlayersList>
Run Code Online (Sandbox Code Playgroud)
我正在尝试删除播放器的所有子节点.我选择了我想要的给定玩家元素
e= root.findall('player')[2]
Run Code Online (Sandbox Code Playgroud)
然后尝试删除所有儿童:
for child in e:
e.remove(child)
Run Code Online (Sandbox Code Playgroud)
然而,每次运行此节点时,只删除少数子节点,而不是全部!为什么?
我可以列出所有子标签及其文本没有问题
for child in e:
print child.tag+':'+child.text
Run Code Online (Sandbox Code Playgroud) 为什么cURL给出正确的响应,但是scrapy却没有?
我要使用javascript抓取的网站填写表格,然后将其发布并验证,然后再提供内容。
在最初的GET请求中从javascript抓取参数后,我已经在python中复制了此js。我的值“ TS644333_75”与js值相匹配(通过执行document.write(..)进行测试,而不是像通常那样进行提交),如果将结果复制并粘贴到cURL中也可以。例如:
curl --http1.0 'http://www.betvictor.com/sports/en/football' -H 'Connection: keep-alive'
-H 'Accept-Encoding: gzip,deflate' -H 'Accept-Language: en'
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
-H 'Referer: http://www.betvictor.com/sports/en/football' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'
--data
'TS644333_id=3&
TS644333_75=286800b2a80cd3334cd2895e42e67031%3Ayxxy%3A3N6QfX3q%3A1685704694&
TS644333_md=1&
TS644333_rf=0&
TS644333_ct=0&
TS644333_pd=0' --compressed
Run Code Online (Sandbox Code Playgroud)
在哪里获取TS644333_75,我只需复制并粘贴模拟js时计算出的python代码的结果即可。
在Wireshark的节目监测的数据包,如图这篇文章在这里(我已经添加了一些行空间,使POST数据更易读,但除此之外,它是为在Wireshark中看到的)。
但是,如果我启动了一个刮y的外壳:
1) scrapy shell "http://www.betvictor.com/sports/en/football"
Run Code Online (Sandbox Code Playgroud)
并构造一个表单请求:
2) from scrapy.http import FormRequest
req=FormRequest(
url='http://www.betvictor.com/sports/en/football',
formdata={
'TS644333_id': '3',
'TS644333_75': '286800b2a80cd3334cd2895e42e67031:yxxy:3N6QfX3q:1685704694',
'TS644333_md': '1',
'TS644333_rf': '0',
'TS644333_ct': '0',
'TS644333_pd': '0'
},
headers={
'Referer': 'http://www.betvictor.com/sports/en/football',
'Connection': …Run Code Online (Sandbox Code Playgroud) Incapsula是一个Web应用程序交付平台,可用于防止抓取。
我在Python和Scrapy中工作,发现了这一点,但它似乎已经过时了,不能与当前的Incapsula一起使用。我使用目标网站测试了Scrapy中间件,但由于中间件无法提取一些混淆的参数,所以出现了IndexErrors。
是否有可能改编该存储库,或者Incapsula现在已更改其操作模式?
我也很好奇如何将请求从chrome开发工具“复制为cURL”到我的目标页面,并且chrome响应包含用户内容,但是curl响应是“封装事件”页面。这是针对最初已清除Cookie的Chrome。
curl 'https://www.radarcupon.es/tienda/fotoprix.com'
-H 'pragma: no-cache' -H 'dnt: 1' -H 'accept-encoding: gzip, deflate, br'
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8'
-H 'upgrade-insecure-requests: 1'
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/62.0.3202.94 Chrome/62.0.3202.94 Safari/537.36'
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
-H 'cache-control: no-cache' -H 'authority: www.radarcupon.es'
--compressed
Run Code Online (Sandbox Code Playgroud)
我期望双方的第一个请求都返回一个类似JavaScript的挑战,该挑战将设置一个cookie,但现在看来它不太起作用?