我想抓取一个没有API的流行网站(比如Quora)并获取一些特定信息并将其转储到文件中 - 比如csv,.txt或.html格式很好:)
例如,只返回Quora用户的所有'Bios'列表,这些用户在其公开信息中列出了职业'UX设计师'.
我如何在Ruby中做到这一点?
我对Ruby&Rails的工作方式有足够的了解.我刚刚完成了一个Rails应用程序 - 主要是我自己编写的.但是,无论想象力如何,我都不是大师.
我了解RegExs等
我正在使用:模块:请求 - 用简化的HTTP请求方法来刮取带有重音字符的网页á é ó ú ê ã等.
我已经尝试encoding: utf-8过没有成功.我仍然在结果中得到这个 字符.
request.get({
uri: url,
encoding: 'utf-8'
// ...
Run Code Online (Sandbox Code Playgroud)
是否有任何配置来修复它?
我不知道这是不是一个问题,但我填写了一个这个模块.还没有答案.:/
我正在使用scrapy 0.20.
我想使用项目加载器
这是我的代码:
l = XPathItemLoader(item=MyItemClass(), response=response)
l.add_value('url', response.url)
l.add_xpath('title',"my xpath")
l.add_xpath('developer', "my xpath")
return l.load_item()
Run Code Online (Sandbox Code Playgroud)
我在json文件中得到了结果.这url是一个清单.这title是一个清单.这developer是一个清单.
如何提取单个值而不是列表?
我应该为此制作项目管道吗?我希望有更快的方法
我正在使用平均堆栈创建一个Web应用程序.它将有一个输入框,用户可以在其中编写任何将存储在mongo db中的内容,然后使用angular显示.它类似于新闻源.因此,用户甚至可以输入我从文本中成功提取的URL并将其转换为链接.我想做像facebook和linkedin那样的事情.

刮取给定的URL并显示其主图像和标题,但这应该以角度完成而不进入节点.
我想知道是否有可能通过用户的IP刮取外部(跨域)页面?
对于购物比较网站,我需要抓一个e-com网站的页面,但是来自服务器的几个请求会让我被禁止,所以我正在寻找方法进行客户端抓取 - 也就是说,请求来自用户的页面IP并发送到服务器进行处理.
我正在尝试从公共站点asx.com.au获取数据
页面http://www.asx.com.au/asx/research/company.do#!/ACB/details包含一个div类"view-content",它包含我需要的信息:
但是当我尝试通过Python查看此页面时urllib2.urlopendiv为空:
import urllib2
from bs4 import BeautifulSoup
url = 'http://www.asx.com.au/asx/research/company.do#!/ACB/details'
page = urllib2.urlopen(url).read()
soup = BeautifulSoup(page, "html.parser")
contentDiv = soup.find("div", {"class": "view-content"})
print(contentDiv)
# the results is an empty div:
# <div class="view-content" ui-view=""></div>
Run Code Online (Sandbox Code Playgroud)
是否可以通过编程方式访问该div的内容?
编辑:根据评论,显示内容通过Angular.js.是否可以通过Python触发该内容的呈现?
我正在处理Scrapy,Privoxy和Tor.我已安装并正常工作.但Tor每次都使用相同的IP连接,因此我很容易被禁止.是否有可能告诉Tor重新连接每个X秒或连接?
谢谢!
编辑配置:对于用户代理池我做了这个:http://tangww.com/2013/06/UsingRandomAgent/ (我必须在评论中说出一个_ init _.py文件),以及对于Privoxy和Tor我遵循http://www.andrewwatters.com/privoxy/(我必须手动创建私人用户和私人组与终端).有效 :)
我的蜘蛛是这样的:
from scrapy.contrib.spiders import CrawlSpider
from scrapy.selector import Selector
from scrapy.http import Request
class YourCrawler(CrawlSpider):
name = "spider_name"
start_urls = [
'https://example.com/listviews/titles.php',
]
allowed_domains = ["example.com"]
def parse(self, response):
# go to the urls in the list
s = Selector(response)
page_list_urls = s.xpath('///*[@id="tab7"]/article/header/h2/a/@href').extract()
for url in page_list_urls:
yield Request(response.urljoin(url), callback=self.parse_following_urls, dont_filter=True)
# Return back and go to bext page in div#paginat ul li.next a::attr(href) and begin again
next_page = …Run Code Online (Sandbox Code Playgroud) 这里的工作是从一个站点中抓取一个 API https://xxx.xxx.xxx/xxx/1.json,https://xxx.xxx.xxx/xxx/1417749.json并将其准确地写入 mongodb。为此,我有以下代码:
client = pymongo.MongoClient("mongodb://127.0.0.1:27017")
db = client["thread1"]
com = db["threadcol"]
start_time = time.time()
write_log = open("logging.log", "a")
min = 1
max = 1417749
for n in range(min, max):
response = requests.get("https:/xx.xxx.xxx/{}.json".format(str(n)))
if response.status_code == 200:
parsed = json.loads(response.text)
inserted = com.insert_one(parsed)
write_log.write(str(n) + "\t" + str(inserted) + "\n")
print(str(n) + "\t" + str(inserted) + "\n")
write_log.close()
Run Code Online (Sandbox Code Playgroud)
但是完成这项任务需要花费大量时间。这里的问题是我怎样才能加快这个过程。
使用 Selenium 后,我决定尝试一下,undetected-chromedriver所以我使用它安装了它
pip install undetected-chromedriver
Run Code Online (Sandbox Code Playgroud)
但是,运行这个简单的脚本
import undetected_chromedriver.v2 as uc
options = uc.ChromeOptions()
options.add_argument('--no-sandbox')
driver = uc.Chrome(options=options)
with driver:
driver.get('https://google.com')
Run Code Online (Sandbox Code Playgroud)
给出错误
selenium.common.exceptions.WebDriverException:消息:未知错误:无法从无法访问的 chrome 连接到 127.0.0.1:37541 的 chrome
使用常规 Selenium 没有问题
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument("--no-sandbox"); # Bypass OS security model
driver = webdriver.Chrome(options=options)
with driver:
driver.get('https://google.com')
Run Code Online (Sandbox Code Playgroud)
这是回溯
Traceback (most recent call last):
File "/root/test-bot/src/test.py", line 6, in <module>
driver = uc.Chrome()
File "/root/anaconda3/envs/test/lib/python3.9/site-packages/undetected_chromedriver/v2.py", line 302, in __init__
super(Chrome, self).__init__(
File "/root/anaconda3/envs/test/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, …Run Code Online (Sandbox Code Playgroud) python selenium web-scraping selenium-chromedriver undetected-chromedriver
我希望连接到网站并下载一些 pdf 文件。该网站允许我们只有登录后才能查看内容。它要求我们使用OTP登录,并且不能同时在超过3台设备上登录。
我想下载列出的所有 pdf 文件。所以我之前尝试过
python playwright open --save-storage websitename.json
Run Code Online (Sandbox Code Playgroud)
保存登录信息。但它不适用于该特定网站。website.json 文件是空的,但它适用于其他网站。
因此,我能想到的唯一解决方案是连接到当前的浏览器,打开该网站,然后下载这些 pdf。
如果您对此有解决方案,甚至有其他方法,请告知。
我也在考虑转行做木偶师。但是,我不知道使用node.js解析html,因为我觉得使用css选择器更舒服,所以我无法切换它。
web-scraping ×10
python ×5
javascript ×2
scrapy ×2
angularjs ×1
jquery ×1
mongodb ×1
node.js ×1
phantomjs ×1
php ×1
puppeteer ×1
pymongo ×1
python-2.7 ×1
python-3.x ×1
request ×1
ruby ×1
selenium ×1
tor ×1
urllib2 ×1